<template>
  <w-pop ref="pop">
    <div class="username">{{ UserData.userName }}</div>
    <div class="muen_list">
      <div class="item" @click="handleGo('/account')" :class="{ active: route.fullPath == '/account' }">
        <!-- :style="{ color: color }" -->
        <SvgIcon name="account" />
        {{ $t("home.account") }}
      </div>
      <div class="item" @click="handleGo('/order')" :class="{ active: route.fullPath == '/order' }">
        <SvgIcon name="order" />
        {{ $t("home.myorder") }}
      </div>
      <div class="item" @click="handleGo('/sendtable')" :class="{ active: route.fullPath == '/sendtable' }">
        <SvgIcon name="send" />
        {{ $t("home.sendtable") }}
      </div>
      <div class="item" @click="handleGo('/history')" :class="{ active: route.fullPath == '/history' }">
        <SvgIcon name="his" />
        {{ $t("home.history") }}
      </div>
      <div class="item" @click="handleGo('/notice')" :class="{ active: route.fullPath == '/notice' }">
        <SvgIcon name="notice" />
        {{ $t("home.notice") }}
      </div>
      <div class="item" @click="handleGo('/editpwd')" :class="{ active: route.fullPath == '/editpwd' }">
        <SvgIcon name="pwd" />
        {{ $t("home.editpwd") }}
      </div>
    </div>
    <el-button class="logout_btn" type="primary" round size="large" @click="handleLogout">登出<el-icon>
        <Right />
      </el-icon></el-button>
  </w-pop>
</template>

<script>
import store from '../store';
import {
  defineComponent,
  ref,
  reactive,
  nextTick,
  onMounted,
  toRaw,
  toRefs,
  watch,
  computed
} from "vue";
import { useRouter, useRoute } from "vue-router";
import { getUserInfoByToken } from '@/api/user'
export default defineComponent({
  setup() {

    const router = useRouter();
    const route = useRoute();

    const pop = ref();
    const color = computed(() => store.getters.themeColor)

    const open = () => {
      init()
      pop.value.open();
      setTimeout(() => {
        if (document.getElementsByClassName('active')[0]) {
          document.getElementsByClassName('active')[0].style.color = color
          document.getElementsByClassName('active')[0].children[0].style.color = color
        }
      }, 500)
    };

    const handleGo = (path) => {
      router.push(path);
    };

    const handleLogout = () => { };
    setTimeout(() => {
    }, 100)

    const UserData = ref({})
    const init = async () => {
      const res = await getUserInfoByToken({})
      if (res) {
        UserData.value = res
      }
    }
    return {
      UserData,
      route,
      color,
      pop,
      open,
      router,
      handleGo,
      handleLogout,
    };
  },
});
</script>
<style scoped lang="scss">
.username {
  position: absolute;
  top: 12px;
  z-index: 1000;
  color: #333;
  font-family: Helvetica;
  font-size: 18px;
  font-style: normal;
  font-weight: 400;
  line-height: normal;
  right: 16px;
}

.muen_list {
  display: flex;
  flex-direction: column;
  padding: 0 17px;

  .item {
    display: flex;
    flex-direction: row;
    align-items: center;
    color: #666666;
    border-bottom: 1px solid #00000014;
    font-size: 16px;
    padding: 16px 0;


    svg {
      margin-right: 12px;
      color: #666666;
    }
  }

  .active {
    color: #A0C460;

    svg {
      color: #A0C460;
    }
  }
}

.logout_btn {
  position: absolute;
  bottom: 0;
  left: 12px;
  bottom: 50px;
}
</style>
